package cn.itedus.lottery.domain.strategy.service.algorithm.impl;

import cn.itedus.lottery.domain.strategy.service.algorithm.BaseAlgorithm;
import org.springframework.stereotype.Component;

import java.security.SecureRandom;
import java.util.Arrays;
import java.util.List;

// 单项概率算法
@Component("singleRateRandomDrawAlgorithm")
public class SingleRateRandomDrawAlgorithm extends BaseAlgorithm {

    @Override
    public String randomDraw(Long strategyId, List<String> excludeAwardIds) {

        // 获取策略对应的元祖
        String[] rateTuple = super.rateTupleMap.get(strategyId);
        assert rateTuple != null;

        // 随机索引
        int randomVal = this.generateSecureRandomIntCode(100);
        System.out.println("randomVal = " + randomVal);
        int idx = super.hashIdx(randomVal); // 返回斐波那契哈希值

        // 返回结果
        String awardId = rateTuple[idx];
        System.out.println("awardId = " + awardId);

        if (excludeAwardIds.contains(awardId)) return null;

        return awardId;
    }
}
